import useFetch, { type FetchOptions } from './useFetch'

export default (options?: Omit<FetchOptions, 'method'>) => {
  const { loading, data, run } = useFetch('/api/v1/base/upload', {
    method: 'POST',
    manual: true,
    ...options,
  })

  /**
   * 上传方法
   * @param file 文件
   * @param filename 文件名称
   */
  const upload = (file: File) => {
    const formdata = new FormData()
    formdata.append('file', file)
    run(formdata)
  }

  return {
    data,
    loading,

    submit: upload,
  }
}
